<template>
	<view class="content bgc-f0">
		<view class="bgc-fff pt30 pb30 pl50 pr50 z-flex z-flex-align-c">
			<u-image :src="storeInfo.img[0]" width="120rpx" height="120rpx"></u-image>
			<view class="flex-1 z-flex z-flex-around ml20" style="flex-direction: column;height: 120rpx;">
				<view class="z-flex pr10">
					<view class="mr10"><text class="fs30 fwb c-333">{{storeInfo.name}}</text></view>
					<view class="_dp">铂金合作店铺</view>
				</view>
				<!-- <text class="fs24 c-666 mr10">可兑换积分：</text> -->
				<view class="c-333 fs24">
					<text>联系人：{{storeInfo.contactsName}}({{storeInfo.contactsPhone}})</text>
				</view>
			</view>
			<view class="_hx" @click="getScanCode"><text>去核销</text></view>
		</view>
		<view class="p20">
			<view class="br12 bgc-fff z-flex z-flex-between pt30 pb10 pl40 pr40" style="flex-wrap: wrap;">
				<template v-for="(it, ind) in selfFunc">
					<view class="_li" @click="handSelfFunc(ind)" :key="ind">
						<view class="_tg">
							<view class="_box">
								<image :src="'/static/icon/'+it.icon+'.png'" mode="" class="w50"></image>
							</view>
						</view>
						<view><text class="fs24 c-666">{{it.name}}</text></view>
					</view>
				</template>
				<view class="_li">
					
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getOneApi } from '@/api/shop.js'
	import { orderWriteOffApi } from '@/api/order.js'
	import { getQueryString } from '@/libs/function.js'
	export default {
		data() {
			return {
				selfFunc: [{
					name: '推广二维码',
					icon: 'w_1'
				}, {
					name: '已售产品',
					icon: 'w_2'
				}, {
					name: '我的客户',
					icon: 'w_3'
				},
				// {
				// 	name: '体验卡查询',
				// 	icon: 'w_4'
				// }, 
				{
					name: '流水查询',
					icon: 'w_5'
				}, {
					name: '核销记录',
					icon: 'w_6'
				}],
				option: {},
				storeInfo: {}
			}
		},
		onLoad(option) {
			option && (this.option = option)
		},
		async onShow() {
			this.$nextTick(this.getStoreInfo)
		},
		methods: {
			async getStoreInfo(){
				const {code,data} = await getOneApi({
					id: uni.getStorageSync('businessId')
				})
				if(code != 0) return
				this.storeInfo = data
			},
			getScanCode(){
				uni.scanCode({
					onlyFromCamera: true,
					success: async (res)=> {
						try{
							// 订单ID
							const orderId = getQueryString(res.result,'b')
							// 门店ID
							const storeId = getQueryString(res.result,'a')
							// 掉核销接口
							uni.showLoading({
								title: '正在核销'
							})
							const {code,data} = await orderWriteOffApi({
								orderId: Number(orderId),
								userId: Number(storeId)
							})
							uni.hideLoading()
							let hxResult = code == 0?'success':'fail'
							setTimeout(()=>{
								uni.$u.route({
									type: 'navigateTo',
									url: 'mapPages/backAdmin/store_info/verifica_success',
									params:{
										type: hxResult
									}
								})
							},500)
						}catch(e){
							uni.showToast({
								title: '请重新核销！',
								icon: 'none'
							})
						}
						
					}
				});
			},
			handSelfFunc(ind) {
				switch (ind) {
					case 0:
						uni.$u.route({
							type: 'navigateTo',
							url: 'mapPages/backAdmin/store_info/ewm',
							params: {
								id: this.option.id
							}
						})
						break;
					case 1:
						uni.$u.route({
							type: 'navigateTo',
							url: 'mapPages/backAdmin/store_info/sold'
						})
						break;
					case 2:
						uni.$u.route({
							type: 'navigateTo',
							url: 'mapPages/backAdmin/store_info/custom'
						})
						break;
					case 3:
						uni.$u.route({
							type: 'navigateTo',
							url: 'mapPages/backAdmin/store_stream/index'
						})
						break;
					case 4:
						uni.$u.route({
							type: 'navigateTo',
							url: 'mapPages/backAdmin/store_info/write_off'
						})
						break;
					default:
						break;
				}

			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: 100vw;
		height: 100vh;

		._dp {
			background-color: #e138aa;
			border-radius: 40rpx;
			color: #FFFFFF;
			font-size: 24rpx;
			width: 190rpx;
			height: 50rpx;
			line-height: 50rpx;
			text-align: center;
		}
		
		._hx{
			width: 120rpx;
			padding: 6rpx 0;
			font-size: 24rpx;
			color: red;
			border: 1rpx solid red;
			text-align: center;
			border-radius: 40rpx;
		}

		._li {
			flex: 1;
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			margin-bottom: 30rpx;

			._tg {
				width: 170rpx;
				height: 170rpx;
				border-radius: 50%;
				background-color: rgba(35, 187, 179, .4);
				display: flex;
				justify-content: center;
				align-items: center;
				margin-bottom: 10rpx;

				._box {
					width: 150rpx;
					height: 150rpx;
					background-color: #FFFFFF;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}

		._li:nth-of-type(3n-1) {
			flex: 2;
		}
	}
</style>
